package utile

import (
	"sync"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

var (
	dbInstance *gorm.DB
	once       sync.Once
	dbError    error
)

// GetDB 返回数据库连接的单例实例
func GetDB() (*gorm.DB, error) {
	once.Do(func() {
		dbInstance, dbError = gorm.Open(mysql.New(mysql.Config{
			DSN: "root:123456@tcp(localhost:3306)/expressage?charset=utf8&parseTime=True&loc=Local",
		}), &gorm.Config{})
	})
	return dbInstance, dbError
}
